<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body onload="verifyToken(),initRole()">
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">资质验证</label>
                            <div class="layui-input-inline" lay-filter="classDiv">
                                <select id="verify" name="verify" lay-filter="classIdFilter">
                                    <option selected>请选择</option>
                                    <option>已申请</option>
                                    <option>已验证</option>
                                    <option>已拒绝</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">单位名称</label>
                            <div class="layui-input-inline">
                                <input type="text" id="name" name="name" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">单位账号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="username" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">组织机构代码</label>
                            <div class="layui-input-inline">
                                <input type="text" id="code" name="code" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter">

        </table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-pass" lay-event="pass">通过</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-refuse" lay-event="refuse">拒绝</a>
        </script>

    </div>
</div>
<script src="../js/lay-module/http/http.js"></script>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;


        table.render({
            elem: '#currentTableId',
            url: $api + 'projectLibrary/enterprise/select/all/enterprise',
            toolbar: '#toolbarDemo',
            headers:{
                Authorization: layui.data('table')['Authorization']
            },
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                // {type: "checkbox", width: 50},
                {type: "numbers" , width: 50},
                {field: "id", title: "主键", hide: true},
                {field: "name" , width: 100, title: '单位名称'},
                {field: 'code', title: '组织机构代码',width: 100, hide: true},
                {field: 'username', width: 100, title: '帐号'},
                {field: 'password', width: 100, title: '密码', hide: true},
                {field: 'economics', width: 100, title: '经济财务数据'},
                {field: 'certification', width: 100, title: '单位资质'},
                {field: 'verify', width: 100, title: '资质是否验证', templet:function (res){
                    return getVerify(res.verify)
                    }
                },
                {field: 'municipalMoney', width: 150, title: '市级资金'},
                {field: 'superiorMoney', width: 150, title: '上级资金'},
                {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 5, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            console.log(result)
            // layer.alert(result, {
            //     title: '最终的搜索信息'
            // });
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    name: data.field.name,
                    code: data.field.code,
                    username: data.field.username,
                    verify: data.field.verify
                },
            }, 'data');

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(JSON.stringify(data))
            if (obj.event === 'pass') {

                $.ajax({
                    type: 'GET',
                    url: $api + 'projectLibrary/enterprise/audit/enterprise?id=' + data.id + '&verify=1',
                    contentType: "application/json;charset=utf-8",
                    async: false,
                    headers: {
                        'Authorization': layui.data('table')['Authorization']
                    },
                    success: function (res) {
                        alert(res.data)
                        window.location.reload($api + 'projectLibrary/enterprise/select/all/enterprise')
                    }
                });

                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'refuse') {

                $.ajax({
                    type: 'GET',
                    url: $api + 'projectLibrary/enterprise/audit/enterprise?id=' + data.id + '&verify=-1',
                    contentType: "application/json;charset=utf-8",
                    async: false,
                    headers: {
                        'Authorization': layui.data('table')['Authorization']
                    },
                    success: function (res) {
                        alert(res.data)
                        window.location.reload($api + 'projectLibrary/enterprise/select/all/enterprise')
                    }
                });

            }
        });

    });
</script>

</body>
</html>